$testService = "http://localhost/CmdletDesigner/cmdlet.asmx"
$testDatasource = ".\SQLEXPRESS"
$testDatabase = "AspenManagement"
$username = "$env:USERDOMAIN\$env:USERNAME"
$sqlCommand = Resolve-Path "..\AspenManagementCmdlets\UnitTests\Scripts\Invoke-SqlCommand.ps1"

## Clean up protected project
$projectId = (Get-PsSpecProject SampleProjectExistingProtectedProject* -Service $testService).Id
if($projectId) { [void] (& $sqlCommand $testDataSource $testDatabase "EXEC RemoveProject '$projectId','SECRETDOMAIN\leeholm'") }
$projectId = (Get-PsSpecProject SampleProjectExistingSharedProject* -Service $testService).Id
if($projectId) { [void] (& $sqlCommand $testDataSource $testDatabase "EXEC RemoveProject '$projectId','SECRETDOMAIN\leeholm'") }
$projectId = (Get-PsSpecProject SampleProjectExistingSpecWriterProject* -Service $testService).Id
if($projectId) { [void] (& $sqlCommand $testDataSource $testDatabase "EXEC RemoveProject '$projectId','SECRETDOMAIN\leeholm'") }

## Create shared projects

## -- Create a project owned by somebody else
& $sqlCommand $testDataSource $testDatabase "EXEC NewProject 'TestProjectExistingProtectedProject','An Existing protected Project','SECRETDOMAIN\leeholm'"
[void] (& $sqlCommand $testDataSource $testDatabase "EXEC NewNoun 'TestProjectProtectedNoun','A protected noun','TestProjectExistingProtectedProject','SECRETDOMAIN\leeholm'")
[void] (& $sqlCommand $testDataSource $testDatabase "EXEC NewNoun 'TestProjectProtectedUnusedNounForDeletion','A protected unused noun for deletion','TestProjectExistingProtectedProject','SECRETDOMAIN\leeholm'")
[void] (& $sqlCommand $testDataSource $testDatabase "EXEC NewNoun 'TestProjectProtectedUnusedNoun','A protected unused noun for cmdlets','TestProjectExistingProtectedProject','SECRETDOMAIN\leeholm'")
[void] (& $sqlCommand $testDataSource $testDatabase "EXEC NewCmdlet @verb='Get',@noun='TestProjectProtectedNoun',@project='TestProjectExistingProtectedProject',@user='SECRETDOMAIN\leeholm'")
[void] (& $sqlCommand $testDataSource $testDatabase "EXEC NewParameter @parameterName='Existing',@cmdletName='Get-TestProjectProtectedNoun',@projectName='TestProjectExistingProtectedProject',@type='Int32',@description='',@aliases='',@allowGlobbing=0,@allowMultiple=0,@allowEmptyCollection=0,@allowEmptyString=0,@allowNull=0,@validateCount='',@validateNotNull=1,@validateNotNullOrEmpty=1,@validateRange='',@validateSet='',@validateLength='',@validatePattern='',@notes='',@isDynamic=1,@user='SECRETDOMAIN\leeholm'")
[void] (& $sqlCommand $testDataSource $testDatabase "EXEC NewProjectUser 'TestProjectExistingProtectedProject','SECRETDOMAIN\somebodyelse','ProjectOwner','SECRETDOMAIN\leeholm'")

## -- Create a project owned by somebody else, but shared to current user
& $sqlCommand $testDataSource $testDatabase "EXEC NewProject 'TestProjectExistingSharedProject','An Existing shared Project','SECRETDOMAIN\leeholm'"
[void] (& $sqlCommand $testDataSource $testDatabase "EXEC NewNoun 'TestProjectSharedNoun','A shared noun','TestProjectExistingSharedProject','SECRETDOMAIN\leeholm'")
[void] (& $sqlCommand $testDataSource $testDatabase "EXEC NewNoun 'TestProjectSharedUnusedNounForDeletion','An unused shared noun for deletion','TestProjectExistingSharedProject','SECRETDOMAIN\leeholm'")
[void] (& $sqlCommand $testDataSource $testDatabase "EXEC NewNoun 'TestProjectSharedUnusedNoun','An unused shared noun','TestProjectExistingSharedProject','SECRETDOMAIN\leeholm'")
[void] (& $sqlCommand $testDataSource $testDatabase "EXEC NewProjectUser 'TestProjectExistingSharedProject','$username','ProjectOwner','SECRETDOMAIN\leeholm'")

## -- Create a project owned by somebody else, but shared to current user as spec writer
& $sqlCommand $testDataSource $testDatabase "EXEC NewProject 'TestProjectExistingSpecWriterProject','An Existing shared spec writer Project','SECRETDOMAIN\leeholm'"
[void] (& $sqlCommand $testDataSource $testDatabase "EXEC NewNoun 'TestProjectSpecWriterNoun','A shared noun','TestProjectExistingSpecWriterProject','SECRETDOMAIN\leeholm'")
[void] (& $sqlCommand $testDataSource $testDatabase "EXEC NewNoun 'TestProjectSpecWriterUnusedNounForDeletion','An unused shared noun for deletion','TestProjectExistingSharedProject','SECRETDOMAIN\leeholm'")
[void] (& $sqlCommand $testDataSource $testDatabase "EXEC NewNoun 'TestProjectSpecWriterUnusedNoun','An unused shared noun','TestProjectExistingSpecWriterProject','SECRETDOMAIN\leeholm'")
[void] (& $sqlCommand $testDataSource $testDatabase "EXEC NewProjectUser 'TestProjectExistingSpecWriterProject','$username','SpecWriter','SECRETDOMAIN\leeholm'")

## -- Create a project owned by somebody else, but shared to current user as help writer
& $sqlCommand $testDataSource $testDatabase "EXEC NewProject 'TestProjectExistingHelpWriterProject','An Existing shared help writer Project','SECRETDOMAIN\leeholm'"
[void] (& $sqlCommand $testDataSource $testDatabase "EXEC NewNoun 'TestProjectHelpWriterNoun','A shared noun','TestProjectExistingHelpWriterProject','SECRETDOMAIN\leeholm'")
[void] (& $sqlCommand $testDataSource $testDatabase "EXEC NewNoun 'TestProjectHelpWriterUnusedNounForDeletion','An unused shared noun for deletion','TestProjectExistingSharedProject','SECRETDOMAIN\leeholm'")
[void] (& $sqlCommand $testDataSource $testDatabase "EXEC NewNoun 'TestProjectHelpWriterUnusedNoun','An unused shared noun','TestProjectExistingHelpWriterProject','SECRETDOMAIN\leeholm'")
[void] (& $sqlCommand $testDataSource $testDatabase "EXEC NewProjectUser 'TestProjectExistingHelpWriterProject','$username','HelpWriter','SECRETDOMAIN\leeholm'")
[void] (& $sqlCommand $testDataSource $testDatabase "EXEC NewCmdlet @verb='Set',@noun='TestProjectHelpWriterUnusedNoun',@project='TestProjectExistingHelpWriterProject',@user='SECRETDOMAIN\leeholm'")
[void] (& $sqlCommand $testDataSource $testDatabase "EXEC NewParameter @projectName='TestProjectExistingHelpWriterProject',@cmdletName='Set-TestProjectHelpWriterUnusedNoun',@parameterName='TestParameter',@type='String',@user='SECRETDOMAIN\leeholm'")

Get-PsSpecCmdlet -Project MySampleProject* -Service $testService | Remove-PsSpecCmdlet -Force -Service $testService 
Get-PsSpecProject -Name MySampleProject* -Service $testService | Remove-PsSpecProject -Force -Service $testService
Get-PsSpecNoun -Name MyProcess* -Service $testService | Remove-PsSpecNoun -Force -Service $testService

New-PsSpecProject -Name MySampleProject -Description "My Test Project" -Service $testService
New-PsSpecNoun -Name MyProcess -Definition "A system process" -Project MySampleProject -Service $testService

New-PsSpecCmdlet -Snapin ProjectCommands -Project MySampleProject `
    -Verb Get `
    -Noun MyProcess -ShortDescription "Gets processes and stuff" `
    -LongDescription "A cmdlet that does a lot of interesting things, including, for example, Getting Processes" `
    -Note "Note: Do not use this on the third Monday of the month." `
    -Service $testService

New-PsSpecCmdlet -Snapin ProjectCommands -Project MySampleProject `
    -Verb Set `
    -Noun MyProcess -ShortDescription "Sets processes and stuff" `
    -LongDescription "A cmdlet that does a lot of interesting things, including, for example, Setting Processes" `
    -SupportsShouldProcess:$true `
    -Note "Note: Do not use this on the second Tuesday of the month." `
    -SpecExamples "Try this, it's fun: Get-MyProcess | Set-MyProcess" `
    -OutputObject "System.String" `
    -OutputObjectDescription "Field1: String`nField2: Int32" `
    -RelatedTo "Get-MyProcess" `
    -Service $testService

Add-PsSpecCmdletParameter -Name ProcessId -CmdletName Set-MyProcess -ProjectName MySampleProject `
    -Type System.Diagnostics.Process -Service $testService
Get-PsSpecCmdletParameter -Name ProcessId -CmdletName Set-MyProcess -ProjectName MySampleProject -Service $testService |
    Set-PsSpecCmdletParameter `
        -Description "A little description of my parameter" `
        -Alias "Id","PID" `
        -AllowGlobbing:$false `
        -AllowMultiple:$true `
        -Dynamic:$false `
        -AllowEmptyCollection:$false `
        -AllowEmptyString:$false `
        -AllowNull:$false `
        -ValidateCount 1,10 `
        -ValidateNotNull:$true `
        -ValidateNotNullOrEmpty:$true `
        -ValidateRange 0,99999 `
        -ValidateSet "These","Will","Not","Be","Used" `
        -ValidateLength 1,500 `
        -ValidatePattern "foo.*[a-zA-Z0-9]*" `
        -Note "This is a note about the parameter" `
        -ServiceUri $testService

$parameterSetEntry = Get-PsSpecCmdletParameterSetEntry -ParameterName ProcessId -CmdletName Set-MyProcess -ProjectName MySampleProject `
    -Service $testService

$parameterSetEntry | Set-PsSpecCmdletParameterSetEntry `
    -ParameterSetName "TestSet" `
    -Mandatory $true `
    -Position 0 `
    -ValueFromPipeline $false `
    -ValueFromPipelineByPropertyName $true `
    -ValueFromRemainingArguments $false `
    -HelpMessage "This is a help message" `
    -HelpMessageBaseName "SomeBaseName" `
    -HelpMessageResourceId "HELPMESSAGE_RESOURCE" `
    -Service $testService

    
Add-PsSpecCmdletParameter -Name ProcessName -CmdletName Set-MyProcess -ProjectName MySampleProject `
    -Type String -Service $testService